<?php defined('BASEPATH') OR exit('No direct script access allowed');

class  Admin_Config extends Admin_Controller{
	
	protected $section = 'config';
	var $namespace = "config";
	
	function __construct(){
		parent::__construct();	
		if($this->current_user->group_id != 1)
			$this->check_access();
		$this->lang->load($this->namespace,$this->lang_current);
		$this->load->model('settings/settings_m');
		
	}	
	function index(){		
		$this->action = 'save|javascript:void(0)|'.lang('global:save')  
						.'+ back|javascript:void(0)|'.lang('global:back');		
		$post = $this->input->post();
		$this->form_validation->set_rules('site_name', lang('global:site_name'), 'required|max_length[40]');
		
		$type =  substr($this->input->post('btnAction'), 0);
		if($type == 'edit'){
			if ($this->form_validation->run() == TRUE)
			{
				//print_r($post);exit;
				unset($post['btnAction']);
				//config
				$this->settings_m->update_list($this->module,$post);
				//email
				$this->settings_m->update_list('email',$post);
			}
		}
		$model = $this->settings_m->get_all($this->module);
		$email_config = $this->settings_m->get_all('email');
		$this->template
			->title(lang('config:name'))
			->set('model',$model)
			->set('email_config',$email_config)
			->append_css('error.css')
			->set('action',$this->action)
			->set_breadcrumb(lang('shop:config'))//$this->uri->uri_string()
			->build($this->controller.'/'.$this->method);
	}
	
}